The disclosed embodiments of the present invention relate to audio signal processing, and more particularly, to an error detection method of a variable-length coding code stream and a related decoding and error detection apparatus.
The Variable-Length Coding (VLC) is a coding method which performs coding upon data by using codewords with various lengths. Specifically speaking, the VLC employs shorter codewords to encode data with higher occurrence probability, and employs longer codewords to encode data with lower occurrence probability. The overall encoding efficiency is improved accordingly. Since lengths of the codewords employed by the VLC are not fixed, the exact data amount required to be decoded is unknown before the decoding process is completed. Conventionally, decoding a data frame may need to look up a coding table based on a codeword, thereby restoring an initial value corresponding to the codeword. By referring to the coding table, information, such as length range of a codeword and the correspondence between the codeword and the initial value, can be obtained. However, if bit reversing or other transmission errors happen to the data of a code stream during transmission, the data amount read by the decoder may be affected, resulting in that the decoded code stream differs from the original code stream.
Specifically, the VLC includes Huffman coding, Shannon-Fano algorithm, Exponential-Golomb coding, etc. Taking the Huffman coding for example, suppose the intraframe source symbols of the original code stream required to be transmitted are a1, a5, a7, a1, a3 and a4, the original code stream 10, 010, 0111, 10, 000 and 001 can be derived by encoding the source symbols according to the correspondence between the source symbols and the codewords in a Huffman coding table (Table 1).
TABLE 1sourceProbabilityHuffmancodewordsymbol aip(ai)codeword Wilength Kia10.20102a20.19112a30.180003a40.170013a50.150103a60.1001104a70.0101114
During the transmission, errors may occur due to channel instability or other reasons, thus resulting in variation of the received code stream. Assuming that the code stream received by the receiving end is composed of 10, 011, 0111, 10, 000 and 001, when decoding the received code stream, the receiving end firstly reads the codeword “10” and derives a corresponding decoded source symbol as a1. Then the receiving end reads the codeword “011”, while no corresponding source symbol can be found in Table 1. Therefore, the receiving end will falsely employ the following bit “0” as part of the present codeword (i.e. the read codeword will be “0110”), and derive a corresponding decoded source symbol as a6. The decoding process continues by sequentially reading the code stream. After 6 codewords are decoded, the derived source symbols are a1, a6, a2, a2, a3 and a3 respectively, while the last bit of the received code stream “1” is unused. Said scenario is an example of how an erroneous decoding takes place, that is, the amount of used (read) data is less than it should be. Besides, the decoded code stream mismatches the original code stream.
Further, assuming that the received code stream is composed of 10, 011, 0011, 10, 000 and 001, the source symbols corresponding to the first 5 codewords are a1, a6, a7, a3 and a3, respectively. The original code stream transmitted from the encoder including 6 codewords; however, only 1 bit “1” is left after the first 5 codewords are decoded based on the received code stream. As the shortest bit-length of the Huffman codeword shown in Table 1 is 2, the decoder of the receiving end therefore needs to take at least 1 bit from the data frame immediately following the present data frame in combination with the remaining 1 bit of the present frame for completing the decoding process of the sixth codeword. Meanwhile, another erroneous situation takes place, that is, the amount of used (read) data is more than it should be. Besides, the decoded code stream mismatches the original code stream.
On the other hand, if the coding table changes in the course of decoding the received code stream, it will lead to mismatch between the decoded code stream and the original code stream.
In practice, the VLC may be applied to various audio formats such as Advanced Audio Coding (AAC), Moving Picture Experts Group Audio Layer III (MP3), Free Lossless Audio Codec (FLAC), etc. There are reasons (e.g. instability of the transmission channel) that may result in erroneous code stream. Further, erroneous storing process of the coding table may result in decoding error of the data frames of the code stream. Both might lead to discontinuity of sound, bursts, or even a system crash.
In order to solve the aforementioned issues, one conventional solution is to add a Cyclic Redundancy Check (CRC) code to the code stream during encoding, and perform a CRC check upon the data frame for detecting whether the data frame contains error bits after the data frame is completely decoded. However, said conventional solution does not detect error until the completion of data frame decoding process, and thus cannot obtain an error detection result during the decoding process. As a result, said conventional solution has disadvantages on the aspect of preventing the normal system operation from being affected by data frame errors.